using FireStarter.Base;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using FireStarterModeller.Test.BO;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.BO.Loaders;
using Habanero.Faces.Base;
using Habanero.Faces.Win;

namespace FireStarterModeller.Test.UI
{
    public class UITestUtils
    {
        public static void SetupTest()
        {
            TestUtilsDomain.WaitForGC();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        public static void SetupFixture()
        {
            ClassDef.ClassDefs.Clear();
            ClassDef.ClassDefs.Add(new XmlClassDefsLoader(BOBroker.GetClassDefsXml(), new DtdLoader()).LoadClassDefs());
            GlobalUIRegistry.ControlFactory = new ControlFactoryWin();
            GlobalRegistry.UIExceptionNotifier = new RethrowingExceptionNotifier();
        }

        public static IBOGridAndEditorControl GetGridAndBOEditorControl(IControlHabanero controlHabanero)
        {
            foreach (object childControl in controlHabanero.Controls)
            {
                if (childControl is IBOGridAndEditorControl)
                {
                    return (IBOGridAndEditorControl) childControl;
                }
            }
            return null;
        }
    }
}